#!/usr/bin/env bash
#
# Copyright (C) 2000-2021 Kern Sibbald
# Copyright (C) 2021-2022 Bacula Systems SA
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Test the masterkey feature of the volume encoding using gnupg
#

TestName="volenc-mkey-test"
JobName=backup
. scripts/functions

if [ "$FORCE_VOLENC" != "yes" ]; then
    echo "Test $TestName disabled because FORCE_VOLENC is not set"
    exit 0
fi

scripts/cleanup
scripts/copy-test-confs
echo "${cwd}/build" >${cwd}/tmp/file-list

$bin/install-key-manager.sh install

sed -i 's/#*volume_regex=.*/volume_regex=TestVolume[0-9]+|Volume[0-9]+/' bin/key-manager.conf

start_test

cat <<END_OF_DATA >$tmp/bconcmds
@output /dev/null
messages
@$out $tmp/log1.out
setdebug level=4 storage=File
setdebug level=1 client
label storage=File volume=TestVolume001
run job=Simple yes
wait
messages
@#
@# now do a restore
@#
@$out $tmp/log2.out
setdebug level=4 storage=File
restore where=$tmp/bacula-restores select all done
yes
wait
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=File
stop_bacula
check_two_logs
check_restore_diff
end_test
